<template>
    <div class="edit-notice">
        <div class="title">{{type == "create" ? "新增" : "编辑"}}公告</div>
        <el-form
            ref="userInfo"
            label-position="right"
            style=""
            label-width="100px"
            :model="noticeInfo">
            <el-form-item
                label="公告标题">
                <el-input v-model="noticeInfo.noticeTitle" placeholder=""></el-input>
            </el-form-item>
            <el-form-item
                label="公告内容">
                <el-input type="textarea" autosize v-model="noticeInfo.noticeContent"></el-input>
            </el-form-item>
            <el-form-item
                label="跳转类型">
                <el-radio class="radio" v-model="noticeInfo.noticeJumpType " :label="1">绝对路径</el-radio>
                <el-radio class="radio" v-model="noticeInfo.noticeJumpType " :label="2">小程序路径</el-radio>
            </el-form-item>
            <el-form-item
                label="跳转路径">
                <el-input v-model="noticeInfo.noticeJumpUrl" placeholder=""></el-input>
            </el-form-item>
            <el-form-item
                label="跳转类型">
                <el-radio class="radio" v-model="noticeInfo.noticeType" :label="0">全部</el-radio>
                <el-radio class="radio" v-model="noticeInfo.noticeType" :label="1">用户端</el-radio>
                <el-radio class="radio" v-model="noticeInfo.noticeType " :label="2">小程序端</el-radio>
            </el-form-item>
            <el-form-item
                label="开始时间">
                <el-date-picker
                    v-model="noticeInfo.startTimes"
                    type="datetime"
                    placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item
                label="截止时间">
                <el-date-picker
                    v-model="noticeInfo.endTimes"
                    type="datetime"
                    placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
        </el-form>
        <div class="btns">
            <el-button @click="cancel">取消</el-button>
            <el-button @click="submit">确认</el-button>
        </div>
    </div>
</template>
<script>
import { str2time } from "@/utils/util.js";
import { insertNoticeApi } from "@/api/api.js";
export default {
    props:{
        type: {
            type: String,
            defult: ''
        },
        noticeInfo: {
            type: Object,
            defult: {}
        }
    },
    data () {
        return {

        }
    },
    created() {
        console.log(this.noticeInfo)
    },
    methods: {
        cancel(type){
            this.$emit('back', type);
        },
        submit(){
            this.noticeInfo.startTimes = str2time(this.noticeInfo.startTimes);
            this.noticeInfo.endTimes = str2time(this.noticeInfo.endTimes);
            insertNoticeApi(this.noticeInfo).then(res => {
                if (res.code === 200) {
                    this.$message({
                        message: this.type == "edit" ? "编辑公告成功，刷新页面" : this.type == "create" ? "新增公告成功，刷新页面" : "操作成功，刷新页面",
                        type: 'success'
                    });
                    this.cancel("update");
                } else {
                    this.$message({
                        message: res.message,
                        type: 'warning'
                    });
                }
            })
        }
    },
}
</script>
<style lang="scss" scoped>
.edit-notice{
    background: #fff;
    padding: 15px;
    .title{
        height: 40px;
        line-height: 40px;
        font-size: 16px;
        margin-bottom: 10px;
    }
    .btns{
        margin: 20px 0;
        text-align: center;
        .el-button{
            margin: 0 30px;
            width: 80px;
        }
    }
}
</style>
